package com.info.protocol.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;

@Getter
@AllArgsConstructor
public enum MessageTypeEnum {

    REQUEST((byte) 1),

    RESPONSE((byte) 2),

    HEART_BEAT((byte) 3);

    private byte code;

    public static MessageTypeEnum getMessageTypeEnumByCode(int code) {
        return Arrays.stream(MessageTypeEnum.values())
                .filter(e -> e.getCode() == code)
                .findFirst()
                .orElseGet(null);
    }
}
